package com.sanyuan.cloud.module.system.dal.mysql.nongmo;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sanyuan.cloud.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.sanyuan.cloud.module.system.controller.app.position.req.CheckRecordReqVO;
import com.sanyuan.cloud.module.system.controller.app.position.vo.CheckRecordRespVO;
import com.sanyuan.cloud.module.system.dal.dataobject.nongmo.SystemPositionCheckRecordDO;
import com.sanyuan.cloud.module.system.enums.nongmo.CommonEnums;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
* @author szw
* @description 针对表【system_position_check_record(标点打卡记录)】的数据库操作Mapper
* @createDate 2025-04-30 11:14:26
* @Entity generator.domain.SystemPositionCheckRecord
*/
@Mapper
public interface SystemPositionCheckRecordMapper extends BaseMapper<SystemPositionCheckRecordDO> {

    default void insertEntity(SystemPositionCheckRecordDO entity) {
        insert(entity);
    }

    default SystemPositionCheckRecordDO selectByPositionIdAndUserId(Long positionId, Long userId,String status){
        return selectOne(new LambdaQueryWrapperX<SystemPositionCheckRecordDO>()
                .eq(SystemPositionCheckRecordDO::getPositionId, positionId)
                .eq(SystemPositionCheckRecordDO::getUserId, userId)
                .eq(SystemPositionCheckRecordDO::getStatus, status)
                .last("limit 1")
        );
    }

    default Long selectCountBetweenTime(String startTime, String endTime){
        return selectCount(new LambdaQueryWrapperX<SystemPositionCheckRecordDO>()
                .eq(SystemPositionCheckRecordDO::getStatus, CommonEnums.BUSINESS_STATUS_1.getCode())
                .geIfPresent(SystemPositionCheckRecordDO::getCreateTime, startTime+" 0:00:00")
                .leIfPresent(SystemPositionCheckRecordDO::getCreateTime, endTime+" 23:59:59")
        );
    }

    List<CheckRecordRespVO> selectListBetweenTime(CheckRecordReqVO reqVO);
    long selectByCount(CheckRecordReqVO reqVO);
}




